var express = require('express');
var router = express.Router();
let maileConfig = require("../maileConfig/maileConfig");
// 引入缓存模块
const LocalStorage = require('node-localstorage').LocalStorage,
localStorage = new LocalStorage('./scratch');
/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('admin');
});
router.all('/zhuce', function (req, res, next) {
  let obj = {};
  if (Object.keys(req.query).length) {
    obj = req.query
  } else {
    obj = req.body;
  }
  console.log(obj);
  res.send('注册');
});

router.get("/email",(req,res)=>{
  // "1760859316@qq.com"
  var uemail = req.query.uemail;
  var code = parseInt(Math.random()*10000); 
   // 放入缓存中
   localStorage.setItem(uemail,code)
  var mail = {
    // 发件人
    from: '<1192719918@qq.com>',
    // 主题
    subject: '注册验证码',//邮箱主题
    // 收件人
    to:uemail,//前台传过来的邮箱
    // 邮件内容，HTML格式
    text: '用'+code+'作为你的验证码'//发送验证码
  };
   maileConfig(mail)
   var data = {
      mes:"发送给成功",
      code:code
   }
   res.send(data)
})

module.exports = router;
